﻿

//在原有DAO 加入下面两个方法
	
	/**
	 * 查询结果集的行数
	 */
	public int getTotalDaoHuoDetails(DaoHuoDetail daoHuoDetail) throws DaoException {
		//logger.debug("getQueryRows()  - run");

		StringBuffer sb = new StringBuffer();
		sb.append("SELECT COUNT(1) FROM SH_YL_DAO_HUO_DETAIL_T WHERE 1=1");
		
		if (null != daoHuoDetail.getDhId() && !daoHuoDetail.getDhId().trim().equals("")) {
		   sb.append(" AND SH_YL_DAO_HUO_DETAIL_T.DH_ID LIKE '%" + daoHuoDetail.getDhId().trim() + "%'");
		}
		if (daoHuoDetail.getWpId() != 0) {
		  sb.append(" AND SH_YL_DAO_HUO_DETAIL_T.WP_ID =" + daoHuoDetail.getWpId());
		}
		if (null != daoHuoDetail.getMingCheng() && !daoHuoDetail.getMingCheng().trim().equals("")) {
		   sb.append(" AND SH_YL_DAO_HUO_DETAIL_T.MING_CHENG LIKE '%" + daoHuoDetail.getMingCheng().trim() + "%'");
		}
		if (daoHuoDetail.getPrice() != 0) {
		  sb.append(" AND SH_YL_DAO_HUO_DETAIL_T.PRICE =" + daoHuoDetail.getPrice());
		}
		if (daoHuoDetail.getDwId() != 0) {
		  sb.append(" AND SH_YL_DAO_HUO_DETAIL_T.DW_ID =" + daoHuoDetail.getDwId());
		}
		if (null != daoHuoDetail.getDanWei() && !daoHuoDetail.getDanWei().trim().equals("")) {
		   sb.append(" AND SH_YL_DAO_HUO_DETAIL_T.DAN_WEI LIKE '%" + daoHuoDetail.getDanWei().trim() + "%'");
		}
		if (daoHuoDetail.getNum() != 0) {
		  sb.append(" AND SH_YL_DAO_HUO_DETAIL_T.NUM =" + daoHuoDetail.getNum());
		}
		if (null != daoHuoDetail.getCgId() && !daoHuoDetail.getCgId().trim().equals("")) {
		   sb.append(" AND SH_YL_DAO_HUO_DETAIL_T.CG_ID LIKE '%" + daoHuoDetail.getCgId().trim() + "%'");
		}
		if (daoHuoDetail.getHgNum() != 0) {
		  sb.append(" AND SH_YL_DAO_HUO_DETAIL_T.HG_NUM =" + daoHuoDetail.getHgNum());
		}

		String sql = sb.toString();
		return queryInt(sql);		
	}
	
	/**
	 * 返回带查询条件的到货单明细结果集并排序
	 */
	public List getDaoHuoDetails(String property, String sortOrder,int limit, int offset,DaoHuoDetail daoHuoDetail) throws DaoException {
		//logger.debug("List getDaoHuoDetails(String property, String sortOrder,int limit, int offset,DaoHuoDetail daoHuoDetail) --run"); 
		
		
		StringBuffer sb = new StringBuffer();
		sb.append("SELECT DHDTL_ID,DH_ID,WP_ID,MING_CHENG,PRICE,DW_ID,DAN_WEI,NUM,CG_ID,HG_NUM  FROM SH_YL_DAO_HUO_DETAIL_T WHERE 1=1");
		
		if (null != daoHuoDetail.getDhId() && !daoHuoDetail.getDhId().trim().equals("")) {
		   sb.append(" AND SH_YL_DAO_HUO_DETAIL_T.DH_ID LIKE '%" + daoHuoDetail.getDhId().trim() + "%'");
		}
		if (daoHuoDetail.getWpId() != 0) {
		  sb.append(" AND SH_YL_DAO_HUO_DETAIL_T.WP_ID =" + daoHuoDetail.getWpId());
		}
		if (null != daoHuoDetail.getMingCheng() && !daoHuoDetail.getMingCheng().trim().equals("")) {
		   sb.append(" AND SH_YL_DAO_HUO_DETAIL_T.MING_CHENG LIKE '%" + daoHuoDetail.getMingCheng().trim() + "%'");
		}
		if (daoHuoDetail.getPrice() != 0) {
		  sb.append(" AND SH_YL_DAO_HUO_DETAIL_T.PRICE =" + daoHuoDetail.getPrice());
		}
		if (daoHuoDetail.getDwId() != 0) {
		  sb.append(" AND SH_YL_DAO_HUO_DETAIL_T.DW_ID =" + daoHuoDetail.getDwId());
		}
		if (null != daoHuoDetail.getDanWei() && !daoHuoDetail.getDanWei().trim().equals("")) {
		   sb.append(" AND SH_YL_DAO_HUO_DETAIL_T.DAN_WEI LIKE '%" + daoHuoDetail.getDanWei().trim() + "%'");
		}
		if (daoHuoDetail.getNum() != 0) {
		  sb.append(" AND SH_YL_DAO_HUO_DETAIL_T.NUM =" + daoHuoDetail.getNum());
		}
		if (null != daoHuoDetail.getCgId() && !daoHuoDetail.getCgId().trim().equals("")) {
		   sb.append(" AND SH_YL_DAO_HUO_DETAIL_T.CG_ID LIKE '%" + daoHuoDetail.getCgId().trim() + "%'");
		}
		if (daoHuoDetail.getHgNum() != 0) {
		  sb.append(" AND SH_YL_DAO_HUO_DETAIL_T.HG_NUM =" + daoHuoDetail.getHgNum());
		}
		
		if (property != null && sortOrder != null) {
			sb.append(" ORDER BY ");
			sb.append(" ");
			sb.append(property);
			sb.append(" ");
			sb.append(sortOrder);
		} else{
			sb.append(" ORDER BY DHDTL_ID DESC ");
		}
		
		//logger.debug("List getDaoHuoDetails(String property, String sortOrder,int limit, int offset)- end"); 
		return queryList(sb.toString(),limit,offset);
	}
	
